// #define print(...)
#define map_t map
class Solution {
public:
    vector<vector<string>> displayTable(vector<vector<string>>& orders) {
        map_t<string,int> menu; /*item, index*/
        map_t<int, vector<int> > tbl;
        for(auto & d: orders){
            menu.insert({d[2], 0});
        }
        int i = 0;
        for(auto &[item,idx]:menu){
            idx = i++;
        }
        for(auto & d: orders){
            auto ti = atoi(d[1].c_str());
            tbl[ti].resize(menu.size());
            tbl[ti][menu[d[2]]] ++;
        }
        
        vector<vector<string>> table(1+tbl.size(), vector<string>());
        auto it = table.begin();
        it->push_back("Table");
        for(auto &m:menu)
            it->push_back(m.first);
        for(auto & [idx,item]:tbl){
            (++it)->push_back(to_string(idx));
            for(auto &n:item)
                it->push_back(to_string(n));
        }
        
        return table;
    }
};
